/*
 * @(#) OfficeAction .java  1.0  2004-4-12
 *
 * Copyright 2003 by LongTop Corporation.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * LongTop Corporation ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with LongTop.
 */
package com.cnc.ssm.web;

import com.cnc.bas.util.Constants;
import com.cnc.bas.web.SecureBaseDispatchAction;
import com.cnc.ssm.ISsmService;
import com.cnc.ssm.model.PwMenu;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
 

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * User: Du bf
 * Date: 2005-3-29
 */
public class MenuAction extends SecureBaseDispatchAction {
    private ISsmService ssmService = null;

    public void setServlet(ActionServlet actionServlet) {
        super.setServlet(actionServlet);
        ssmService = (ISsmService) this.getBean(Constants.BEAN_NAME_SSM);
    }

    public ActionForward listMenuTree(ActionMapping mapping,
                                      ActionForm form,
                                      HttpServletRequest request,
                                      HttpServletResponse response) throws Exception {
        List list = ssmService.listMenuTree();
        request.setAttribute("list", list);
        return mapping.findForward("list");
    }

    public ActionForward add(ActionMapping mapping,
                             ActionForm form,
                             HttpServletRequest request,
                             HttpServletResponse response) throws Exception {
        PwMenu param = ((MenuForm) form).getMenu();
        ssmService.addMenu(param);
        return mapping.findForward("edit");
    }

    public ActionForward update(ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response) throws Exception {
        PwMenu param = ((MenuForm) form).getMenu();
        ssmService.updateMenu(param);
        return mapping.findForward("edit");
    }

    public ActionForward delete(ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response) throws Exception {
        String id = request.getParameter("ID");
        ssmService.deleteMenu(id);
        request.setAttribute("deleteFlg", "true");
        return mapping.findForward("edit");
    }

    public ActionForward edit(ActionMapping mapping,
                              ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        String id = request.getParameter("ID");
        PwMenu obj = ssmService.loadMenu(id);
        ((MenuForm) form).setMenu(obj);
        return mapping.findForward("edit");
    }

    public ActionForward create(ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response) throws Exception {
        return mapping.findForward("edit");
    }


}
